
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Spring拦截链如何实现？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Spring拦截链如何实现？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Spring 拦截链（Interceptor Chain）机制的主要作用是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它是一种在请求处理的生命周期中执行自定义逻辑的机制，允许在不同阶段插入代码，常用于实现日志记录、权限检查、性能监控等通用功能。</div>
          </div>
          <div class="card-source">来源: 文档中「Spring 拦截链」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在 Spring 中，自定义拦截器通常需要实现哪个接口？该接口定义了哪三个核心方法？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">自定义拦截器通常需要实现 `HandlerInterceptor` 接口。该接口定义的三个核心方法是 `preHandle`、`postHandle` 和 `afterCompletion`。</div>
          </div>
          <div class="card-source">来源: 文档中「Spring 拦截链的实现机制 - 拦截器的定义」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">HandlerInterceptor接口中的`preHandle`方法在何时被调用？其布尔类型的返回值有何作用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`preHandle`方法在请求处理之前被调用。返回`true`表示继续处理请求，而返回`false`则表示请求被终止。</div>
          </div>
          <div class="card-source">来源: 文档中「Spring 拦截链的实现机制 - 拦截器的定义」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">`HandlerInterceptor`接口中的`postHandle`方法在请求生命周期的哪个阶段执行？它有什么主要用途？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`postHandle`方法在请求处理之后、视图渲染之前被调用。它的主要用途是可以在此阶段修改模型和视图（ModelAndView）信息。</div>
          </div>
          <div class="card-source">来源: 文档中「Spring 拦截链的实现机制 - 拦截器的定义」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">如何在 Spring MVC 应用中配置并注册一个自定义的拦截器？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过实现`WebMvcConfigurer`接口并重写其`addInterceptors`方法。在该方法内，使用`InterceptorRegistry`对象来添加自定义拦截器，并可以配置其拦截的URL模式，例如 `registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");`。</div>
          </div>
          <div class="card-source">来源: 文档中「Spring 拦截链的实现机制 - 配置拦截器」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在一个拦截器链中，如果某个拦截器的`preHandle`方法返回了`false`，会产生什么后果？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">如果任何拦截器的`preHandle`方法返回`false`，请求会被终止，后续的拦截器和请求处理器（Controller）都会被跳过。</div>
          </div>
          <div class="card-source">来源: 文档中「Spring 拦截链的实现机制 - 拦截链的执行顺序」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">请列举文档中提到的至少三种 Spring 拦截器的典型应用场景。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中提到的典型应用场景包括：日志记录（记录请求信息）、权限控制（检查用户权限）、性能监控（监控请求处理时间）和请求修改（添加默认值或自定义headers）。</div>
          </div>
          <div class="card-source">来源: 文档中「Spring 拦截链的实现机制 - 应用场景」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">`HandlerInterceptor`接口中的`afterCompletion`方法何时被调用，通常用于什么操作？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`afterCompletion`方法在请求完成之后（视图渲染之后）被调用，通常可以用于进行资源清理等操作。</div>
          </div>
          <div class="card-source">来源: 文档中「Spring 拦截链的实现机制 - 拦截器的定义」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">根据文档，当存在多个拦截器时，`preHandle`、`postHandle`和`afterCompletion`方法的执行顺序是怎样的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">根据文档，`preHandle`、`postHandle`和`afterCompletion`方法都按照拦截器被添加的顺序依次执行。</div>
          </div>
          <div class="card-source">来源: 文档中「Spring 拦截链的实现机制 - 拦截链的执行顺序」部分</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
